package org.snail.department.service.message;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

@Data
@Log4j
/**
 *  部门队列消息分装
 */
public class DeptInfoMessageCreator implements MessageCreator {

    private Object sendObject;

    @Override
    /**
     * 封装消息
     */
    public Message createMessage(Session session) throws JMSException {
        Message msg = null;
        try {
            if (null == sendObject) {
                log.error("部门同步：activemq传入参数为空！");
            } else {
                msg = session.createTextMessage(JSON.toJSONString(sendObject));
            }
        } catch (JMSException e) {
            log.error("封装对象失败", e);
        }
        return msg;
    }

}
